home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / TGE129C.ZIP / SOURCE / TGEMOUSE.ASM < prev    next >
Assembly Source File  |  1993-08-20  |  6KB  |  330 lines

  1. ; TGEMOUSE.ASM
  2. ; Assorted routines for interfacing to a Microsoft-compatible mouse driver.
  3. ; Copyright (c) 1993 by Matthew Hildebrand
  4. ; Turbo Assembler syntax
  5.  
  6.  
  7. IDEAL
  8. P486N        ; 286 code, but we want 486 alignment
  9. MODEL    LARGE
  10.  
  11.  
  12.     CODESEG
  13.  
  14. ; resets the mouse driver.  Returns 1 if mouse installed, 0 if not
  15. ; int resetMouse(void);
  16.     PUBLIC    C    TGE_resetMouse
  17. PROC    C    TGE_resetMouse
  18.   xor    ax,ax
  19.   int    33h
  20.   cmp    ax,0FFFFh
  21.   jne    @@L1
  22.   mov    ax,1
  23.   retcode
  24.     @@L1:
  25.   xor    ax,ax
  26.   retcode
  27. ENDP
  28.  
  29. ; returns the number of buttons on the mouse
  30. ; CAUTION!  Also resets the mouse
  31. ; int getButtonsMouse(void);
  32.     PUBLIC    C    TGE_getButtonsMouse
  33. PROC    C    TGE_getButtonsMouse
  34.   xor    ax,ax
  35.   int    33h
  36.   mov    al,bl
  37.   xor    ah,ah
  38.   retcode
  39. ENDP
  40.  
  41. ; shows the mouse pointer
  42. ; void showMouse(void);
  43.     PUBLIC    C    TGE_showMouse
  44. PROC    C    TGE_showMouse
  45.   mov    ax,1
  46.   int    33h
  47.   retcode
  48. ENDP
  49.  
  50. ; hides the mouse pointer
  51. ; void hideMouse(void);
  52.     PUBLIC    C    TGE_hideMouse
  53. PROC    C    TGE_hideMouse
  54.   mov    ax,2
  55.   int    33h
  56.   retcode
  57. ENDP
  58.  
  59. ; returns the current mouse (x,y) coordinates
  60. ; void getPosMouse(int far *x, int far *y);
  61.     PUBLIC    C    TGE_getPosMouse
  62. PROC    C    TGE_getPosMouse
  63.     ARG    x:DATAPTR, y:DATAPTR
  64.   mov    ax,3
  65.   int    33h
  66.   les    bx,[x]
  67.   mov    [es:bx],cx
  68.   les    bx,[y]
  69.   mov    [es:bx],dx
  70.   leave
  71.   retcode
  72. ENDP
  73.  
  74. ; returns true if a button is pressed
  75. ; int buttonMouse(void);
  76.     PUBLIC    C    TGE_buttonMouse
  77. PROC    C    TGE_buttonMouse
  78.   mov    ax,3
  79.   int    33h
  80.   test    bl,1
  81.   jz    @@L1
  82.   mov    ax,1
  83.   retcode
  84.  
  85.     @@L1:
  86.   test    bl,2
  87.   jz    @@L2
  88.   mov    ax,2
  89.   retcode
  90.       @@L2:
  91.   test    bl,4
  92.   jz    @@L3
  93.   mov    ax,3
  94.   retcode
  95.       @@L3:
  96.   xor    ax,ax
  97.   retcode
  98. ENDP
  99.  
  100. ; returns true if the left button is pressed
  101. ; int leftButtonMouse(void);
  102.     PUBLIC    C    TGE_leftButtonMouse
  103. PROC    C    TGE_leftButtonMouse
  104.   mov    ax,3
  105.   int    33h
  106.   test    bl,1
  107.   jnz    @@L1
  108.   xor    ax,ax
  109.   retcode
  110.     @@L1:
  111.   mov    ax,1
  112.   retcode
  113. ENDP
  114.  
  115. ; returns true if the right button is pressed
  116. ; int rightButtonMouse(void);
  117.     PUBLIC    C    TGE_rightButtonMouse
  118. PROC    C    TGE_rightButtonMouse
  119.   mov    ax,3
  120.   int    33h
  121.   test    bl,2
  122.   jnz    @@L1
  123.   xor    ax,ax
  124.   retcode
  125.     @@L1:
  126.   mov    ax,1
  127.   retcode
  128. ENDP
  129.  
  130. ; returns true if the center button is pressed
  131. ; int centerButtonMouse(void);
  132.     PUBLIC    C    TGE_centerButtonMouse
  133. PROC    C    TGE_centerButtonMouse
  134.   mov    ax,3
  135.   int    33h
  136.   test    bl,4
  137.   jnz    @@L1
  138.   xor    ax,ax
  139.   retcode
  140.     @@L1:
  141.   mov    ax,1
  142.   retcode
  143. ENDP
  144.  
  145. ; sets the position of the mouse pointer
  146. ; void setPosMouse(unsigned x,unsigned y);
  147.     PUBLIC    C    TGE_setPosMouse
  148. PROC    C    TGE_setPosMouse
  149.     ARG    x:WORD, y:WORD
  150.   mov    ax,4
  151.   mov    cx,[x]
  152.   mov    dx,[y]
  153.   int    33h
  154.   leave
  155.   retcode
  156. ENDP
  157.  
  158. ; Returns the button press counter.
  159. ; unsigned buttonPressMouse(unsigned button, far *x, far *y);
  160.     PUBLIC    C    TGE_buttonPressMouse
  161. PROC    C    TGE_buttonPressMouse
  162.     ARG    button:WORD, x:DATAPTR, y:DATAPTR
  163.   mov    ax,5
  164.   mov    bx,[button]
  165.   dec    bx
  166.   int    33h
  167.   mov    ax,bx                ; save press counter for return
  168.   les    bx,[x]
  169.   mov    [es:bx],cx            ; x coordinate
  170.   les    bx,[y]
  171.   mov    [es:bx],dx            ; y coordinate
  172.   leave
  173.   retcode
  174. ENDP
  175.  
  176. ; Returns the button release counter.
  177. ; unsigned buttonReleaseMouse(unsigned button, far *x, far *y);
  178.     PUBLIC    C    TGE_buttonReleaseMouse
  179. PROC    C    TGE_buttonReleaseMouse
  180.     ARG    button:WORD, x:DATAPTR, y:DATAPTR
  181.   mov    ax,6
  182.   mov    bx,[button]
  183.   dec    bx
  184.   int    33h
  185.   mov    ax,bx                ; save release counter for return
  186.   les    bx,[x]
  187.   mov    [es:bx],cx            ; x coordinate
  188.   les    bx,[y]
  189.   mov    [es:bx],dx            ; y coordinate
  190.   leave
  191.   retcode
  192. ENDP
  193.  
  194. ; set the horizontal limits for the mouse pointer
  195. ; void setHorizLimitsMouse(unsigned min,unsigned max);
  196.     PUBLIC    C    TGE_setHorizLimitsMouse
  197. PROC    C    TGE_setHorizLimitsMouse
  198.     ARG    min:WORD, max:WORD
  199.   mov    ax,7
  200.   mov    cx,[min]
  201.   mov    dx,[max]
  202. ;  shl    dx,1                ; adjust for mode 13h bug
  203.   int    33h
  204.   leave
  205.   retcode
  206. ENDP
  207.  
  208. ; set the vertical limits for the mouse pointer
  209. ; void setVertLimitsMouse(unsigned min,unsigned max);
  210.     PUBLIC    C    TGE_setVertLimitsMouse
  211. PROC    C    TGE_setVertLimitsMouse
  212.     ARG    min:WORD, max:WORD
  213.   mov    ax,8
  214.   mov    cx,[min]
  215.   mov    dx,[max]
  216.   int    33h
  217.   leave
  218.   retcode
  219. ENDP
  220.  
  221. ; set the graphics pointer shape
  222. ; void setPointerMouse(int xoff,int yoff,void *p);
  223.     PUBLIC    C    TGE_setPointerMouse
  224. PROC    C    TGE_setPointerMouse
  225.     ARG    xOff:WORD, yOff:WORD, p:DATAPTR
  226.   mov    ax,9
  227.   mov    bx,[xOff]
  228.   mov    cx,[yOff]
  229.   les    dx,[p]
  230.   int    33h
  231.   leave
  232.   retcode
  233. ENDP
  234.  
  235. ; Returns the size of the mouse save state buffer
  236.     PUBLIC    C    TGE_getSaveSizeMouse
  237. PROC    C    TGE_getSaveSizeMouse
  238.   mov    ax,0015h
  239.   int    33h
  240.   mov    ax,bx
  241.   retcode
  242. ENDP
  243.  
  244. ; Save the current state of the mouse driver
  245.     PUBLIC    C    TGE_saveStateMouse
  246. PROC    C    TGE_saveStateMouse
  247.     ARG    data:DATAPTR
  248.   mov    ax,0016h
  249.   les    dx,[data]
  250.   int    33h
  251.   leave
  252.   retcode
  253. ENDP
  254.  
  255. ; Restore the state of the mouse driver
  256.     PUBLIC    C    TGE_restoreStateMouse
  257. PROC    C    TGE_restoreStateMouse
  258.     ARG    data:DATAPTR
  259.   mov    ax,0017h
  260.   les    dx,[data]
  261.   int    33h
  262.   leave
  263.   retcode
  264. ENDP
  265.  
  266. ; Set the mickeys to pixels ratio (mickeys/8 pixels)
  267. ; void setRatioMouse(unsigned horiz, unsigned vert);
  268.     PUBLIC    C    TGE_setRatioMouse
  269. PROC    C    TGE_setRatioMouse
  270.       ARG    horiz:WORD, vert:WORD
  271.   mov    ax,000Fh
  272.   mov    cx,[horiz]
  273.   mov    dx,[vert]
  274.   int    33h
  275.   leave
  276.   retcode
  277. ENDP
  278.  
  279. ; Get the mouse sensitivity (mickeys/8 pixels)
  280. ; void getSensitivityMouse(unsigned far *horiz, unsigned far *vert,
  281. ;   unsigned far *doubleSpeed);
  282.     PUBLIC    C    TGE_getSensitivityMouse
  283. PROC    C    TGE_getSensitivityMouse
  284.       ARG    horiz:DATAPTR, vert:DATAPTR, doubleSpeed:DATAPTR
  285.   push    di
  286.  
  287.   mov    ax,001Bh
  288.   int    33h
  289.   les    di,[horiz]
  290.   mov    [es:di],bx
  291.   les    di,[vert]
  292.   mov    [es:di],cx
  293.   les    di,[doubleSpeed]
  294.   mov    [es:di],dx
  295.  
  296.   pop    di
  297.   leave
  298.   retcode
  299. ENDP
  300.  
  301. ; same as resetMouse(), but no initialization of mouse hardware
  302. ; void softResetMouse(void);
  303.     PUBLIC    C    TGE_softResetMouse
  304. PROC    C    TGE_softResetMouse
  305.   mov    ax,21h
  306.   int    33h
  307.   retcode
  308. ENDP
  309.  
  310. ; waits for the specified button to be released before returning
  311. ; void waitReleaseMouse(int button);
  312.     PUBLIC    C    TGE_waitReleaseMouse
  313. PROC    C    TGE_waitReleaseMouse
  314.     ARG    button:WORD
  315.   dec    [button]
  316.     @@L1:
  317.   mov    ax,3
  318.   int    33h
  319.   mov    cx,[button]
  320.   mov    dx,1
  321.   shl    dx,cl
  322.   and    bx,dx
  323.   or    bx,bx
  324.   jnz    @@L1
  325.   leave
  326.   retcode
  327. ENDP
  328.  
  329. ENDS
  330. END